﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gasco.DataAccess;

namespace Gasco.Business.Workflows
{
    public enum WorkflowTypes
    {
        DDP = 1,
        FOB = 2,
        EXW = 3
    }

    public static class WorkflowFactory
    {
        public static IOrderWorkflow LoadOrderWorkflow(order o)
        {
            var db = DatabaseHelper.GetData();

            IQueryable<contract_type> result = from ct in db.contract_types
                                               where ct.id == o.contract_type_id
                                               select ct;

            contract_type contractType = result.FirstOrDefault<contract_type>();
            
            switch (contractType.workflow_type_id)
            {
                case (int)WorkflowTypes.FOB:
                    return new FOBWorkflow(o);
                case (int)WorkflowTypes.DDP:
                    return new DDPWorkflow(o);
                case (int)WorkflowTypes.EXW:
                    return new EXWWorkflow(o);
                default:
                    throw new InvalidOperationException("Can't create specified workflow type id:" + contractType.workflow_type_id);
            }
        }
    }
}
